package com.sukaiyi.generator.utils;

import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;

/**
 * @author sukaiyi
 */
public class PsiDirectoryUtils {
    public static PsiDirectory getChildByName(PsiDirectory dir, String name) {
        if ("..".equals(name)) {
            return dir.getParent();
        }
        PsiElement[] children = dir.getChildren();
        for (PsiElement child : children) {
            if (child instanceof PsiDirectory) {
                if (((PsiDirectory) child).getName().equals(name)) {
                    return (PsiDirectory) child;
                }
            }
        }
        return dir.createSubdirectory(name);
    }
}
